/*
This do file cleans and analyses Senegal dataset for the year 2005
*/

set more off

//CRUCIAL - set path to working folder(point to where the dataset is located on your computer)

* rename variables
 ren v006 Month_intvw
 ren v007 Year_intvw
 ren v010 RBirth_Year
 ren v012 RCurrent_Age
 ren v013 RAge_group
 ren v106 Education_level
 ren v130 Religion
 ren v501 marital_status
 ren b4 Sex_of_child
 ren m70 Check_2mths
 ren b1 Cmonth_birth
 ren b2 Cyear_birth
 ren m15 Cplc_delivery
 ren h0 rcvd_OPV0
 ren h2 rcvd_BCG
 ren h3 rcvd_DTP1
 ren h4 rcvd_OPV1
 ren h5 rcvd_DTP2
 ren h6 rcvd_OPV2
 ren h7 rcvd_DTP3
 ren h8 rcvd_OPV3
 ren h9 rcvd_MEASLES
 ren v190 wealth_index
 ren h1 Health_card
 ren v467d Dstnc_hfcilty
 
 *generate age of the child in months (date of interview-date of birth of child) 
 
 gen agemonth= v008-b3
 
  *generate alive children children aged 12-23 months
 gen C_age=0
 replace C_age= 1 if agemonth >=12 & agemonth<=23
 
 *drop children <12 &>23 months
 drop if C_age ==0
 
 * drop dead children (remain with living children aged 12-23 months)
 drop if b5==0
 
 *generate weighting variable
generate wgt = v005/1000000 
 
 *make unique strata values by region/urban-rural (label option automatically labels the results)
egen strata = group(v024 v025), label

 *tell Stata the weight (using pweights for robust standard errors), cluster (psu), and strata:
svyset [pweight=wgt], psu(v021) strata(strata)
 
* generate date of vaccination 
gen date_BCG = mdy(h2m,h2d,h2y)
gen date_opv0= mdy(h0m,h0d,h0y)
gen date_opv1= mdy(h4m,h4d,h4y)
gen date_opv2 = mdy(h6m,h6d,h6y)
gen date_opv3= mdy(h8m,h8d,h8y)
gen date_dpt1= mdy(h3m,h3d,h3y)
gen date_dpt2= mdy(h5m,h5d,h5y)
gen date_dpt3= mdy(h7m,h7d,h7y)
gen date_measles= mdy(h9m,h9d,h9y)

format date_BCG date_opv0 date_opv1 date_opv2 date_opv3 date_dpt1 ///
date_dpt2 date_dpt3 date_measles %dd_l_CY

*****Generatng vaccinated or not by antigen**
gen bcg_vac=.
replace bcg_vac=0 if (rcvd_BCG==.|rcvd_BCG==0 | rcvd_BCG==3 | ///
rcvd_BCG==8 |rcvd_BCG==9) 
replace bcg_vac=1 if (rcvd_BCG==1|rcvd_BCG==2)
label define bcg_vac 0 "not vaccinated"  1 "vaccinated",modify
label values bcg_vac bcg_vac

gen dpt1_vac=.
replace dpt1_vac=0 if (rcvd_DTP1==.|rcvd_DTP1==0 | rcvd_DTP1==3 | ///
rcvd_DTP1==8 |rcvd_DTP1==9)
replace dpt1_vac=1 if (rcvd_DTP1==1|rcvd_DTP1==2)
label define dpt1_vac 0 "not vaccinated"  1 "vaccinated",modify
label values dpt1_vac dpt1_vac

gen dpt2_vac=.
replace dpt2_vac=0 if (rcvd_DTP2==.|rcvd_DTP2==0 | rcvd_DTP2==3 | ///
rcvd_DTP2==8 |rcvd_DTP2==9)
replace dpt2_vac=1 if (rcvd_DTP2==1|rcvd_DTP2==2)
label define dpt2_vac 0 "not vaccinated"  1 "vaccinated",modify
label values dpt2_vac dpt2_vac


gen dpt3_vac=.
replace dpt3_vac=0 if (rcvd_DTP3==.|rcvd_DTP3==0 | rcvd_DTP3==3 | ///
rcvd_DTP3==8 |rcvd_DTP3==9)
replace dpt3_vac=1 if (rcvd_DTP3==1|rcvd_DTP3==2)
label define dpt3_vac 0 "not vaccinated"  1 "vaccinated",modify
label values dpt3_vac dpt3_vac


gen opv0_vac=.
replace opv0_vac=0 if (rcvd_OPV0==.| rcvd_OPV0==0| rcvd_OPV0==3| ///
rcvd_OPV0==8| rcvd_OPV0==9)
replace opv0_vac=1 if (rcvd_OPV0==1| rcvd_OPV0==2)
label define opv0_vac 0 "not vaccinated"  1 "vaccinated",modify
label values opv0_vac opv0_vac


gen opv1_vac=.
replace opv1_vac=0 if (rcvd_OPV1==.| rcvd_OPV1==0| rcvd_OPV1==3| ///
rcvd_OPV1==8| rcvd_OPV1==9)
replace opv1_vac=1 if (rcvd_OPV1==1| rcvd_OPV1==2)
label define opv1_vac 0 "not vaccinated"  1 "vaccinated",modify
label values opv1_vac opv1_vac


gen opv2_vac=.
replace opv2_vac=0 if (rcvd_OPV2==.| rcvd_OPV2==0| rcvd_OPV2==3| ///
rcvd_OPV2==8| rcvd_OPV2==9)
replace opv2_vac=1 if (rcvd_OPV2==1| rcvd_OPV2==2)
label define opv2_vac 0 "not vaccinated"  1 "vaccinated",modify
label values opv2_vac opv2_vac


gen opv3_vac=.
replace opv3_vac=0 if (rcvd_OPV3==.| rcvd_OPV3==0| rcvd_OPV3==3| ///
rcvd_OPV3==8| rcvd_OPV3==9)
replace opv3_vac=1 if (rcvd_OPV3==1| rcvd_OPV3==2)
label define opv3_vac 0 "not vaccinated"  1 "vaccinated",modify
label values opv3_vac opv3_vac


gen measles_vac=.
replace measles_vac=0 if (rcvd_MEASLES==.|rcvd_MEASLES==0| ///
rcvd_MEASLES==3|rcvd_MEASLES==8|rcvd_MEASLES==9)
replace measles_vac=1 if (rcvd_MEASLES==1|rcvd_MEASLES==2)
label define measles_vac 0 "not vaccinated"  1 "vaccinated",modify
label values measles_vac measles_vac

******generating immunization status for only BCG, OPV1, OPV2, OPV3, DPT1, DPT2, DPT3 and Measles
gen immunization_status1=.
replace immunization_status1=0 if (bcg_vac==0& dpt1_vac==0& ///
dpt2_vac==0& dpt3_vac==0& opv1_vac==0& opv2_vac==0& opv3_vac==0& measles_vac==0)
replace immunization_status1=1 if (bcg_vac==1|dpt1_vac==1| ///
dpt2_vac==1|dpt3_vac==1|opv1_vac==1|opv2_vac==1|opv3_vac==1|measles_vac==1)
replace immunization_status1=2 if (bcg_vac==1 & dpt1_vac==1& ///
dpt2_vac==1& dpt3_vac==1& opv1_vac==1& opv2_vac==1& opv3_vac==1& measles_vac==1)
label define immunization_status1 0 "not immunized"  1 "partially immunized" 2 "fully immunized", modify
label values immunization_status1 immunization_status1

*****generate non- or under-immunized and fully immunized

gen immunization_status2=.
replace immunization_status2=0 if (immunization_status1==0 | immunization_status1==1)
replace immunization_status2=1 if (immunization_status1==2)
labe define immunization_status2 0 "non- or under-immunized" 1 "fully immunized"
label values immunization_status2 immunization_status2

*****vaccination coverage for each vaccine
tab bcg_vac [iweight=wgt]

tab dpt1_vac [iweight=wgt]

tab dpt2_vac [iweight=wgt]

tab dpt3_vac [iweight=wgt]

tab opv1_vac [iweight=wgt]

tab opv2_vac [iweight=wgt]

tab opv3_vac [iweight=wgt]

tab measles_vac [iweight=wgt]

******received all 8 vaccines
tab immunization_status1 [iweight=wgt]

tab immunization_status2 [iweight=wgt]


 **** generate county
gen Country="SENEGAL" 
 
keep v005 v021 v022 v023 v024 v025 agemonth C_age ///
wgt strata date_BCG date_opv0 date_opv1 date_opv2 ///
date_opv3 date_dpt1 date_dpt2 date_dpt3 date_measles ///
bcg_vac dpt1_vac dpt2_vac dpt3_vac opv0_vac opv1_vac ///
opv2_vac opv3_vac measles_vac immunization_status1 ///
immunization_status2 Country

 
 
